/**
 * $Id$
 * Copyright 2011-2014 Oak Pacific Interactive. All rights reserved.
 */
package com.malphi.framework.core.xmlconfig.impl;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;


/**
 * @author <a href="mailto:ruofei.ma@renren-inc.com">ma ruofei</a>
 * @version 1.0 2011-11-21 上午11:19:18
 * @since 1.0
 */
public class MemCachePoolConfig implements Serializable{

    private static final long serialVersionUID = 4546578640814986336L;
    
    private String poolName;
    
    private List<PoolNode> poolNodes;
    
    public MemCachePoolConfig(String poolName, PoolNode... nodes) {
        this.poolName = poolName;
        this.poolNodes = Arrays.asList(nodes);
    }
    
    public MemCachePoolConfig() {
    }

    public String getPoolName() {
        return poolName;
    }
    
    public void setPoolName(String poolName) {
        this.poolName = poolName;
    }

    
    public List<PoolNode> getPoolNodes() {
        return poolNodes;
    }

    public void setPoolNodes(List<PoolNode> poolNodes) {
        this.poolNodes = poolNodes;
    }
    public String[] getServers(){
        String[] servers = new String[poolNodes.size()];
        for (int i = 0; i <poolNodes.size(); i++) {
            servers[i] = poolNodes.get(i).getServer();
        }
        return servers;
    }
    
    @Override
    public String toString() {
        return "MemCachePoolConfig [poolNodes=" + poolNodes+ ", poolName=" + poolName + "]";
    }
    
    public static class PoolNode implements Serializable{

        private static final long serialVersionUID = 958094661523431914L;
        
        private static final String SPLIT = ":";
        
        private String host;
        private int port;
        private int connectionNum;
        
        public String getHost() {
            return host;
        }
        
        public void setHost(String host) {
            this.host = host;
        }
        
        public int getPort() {
            return port;
        }
        
        public void setPort(int port) {
            this.port = port;
        }
        
        public int getConnectionNum() {
            return connectionNum;
        }
        
        public void setConnectionNum(int connectionNum) {
            this.connectionNum = connectionNum;
        }
        
        public String getServer(){
            return new StringBuilder(host).append(SPLIT).append(port).toString();
        }
        
        @Override
        public String toString() {
            return "PoolNode [hostName=" + host + ", port=" + port + ", connectionNum=" + connectionNum + "]";
        }
    }

    
}
